﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MapHello.Core
{
    abstract class AsyncTask : IDisposable
    {
        public Guid Id { get; set; }
        public int Interval { get; set; }
        public TaskState TaskState { get; set; }
        public object State { get; set; }
        public Exception Exception { get; set; }
        public MapHelloEventArgs Args { get; set; }
        public bool IsSystem { get; set; }

        public AsyncTask()
        {
            Id = Guid.NewGuid();
        }

        public abstract void Run(object state);


        public void Dispose()
        {

        }

        public void NotifyCompletion()
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                this.ProtectedNotifyCompletion();
            });
        }

        protected abstract void ProtectedNotifyCompletion();
        
    }
}
